/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.quician.webapp.ejbs;

import com.quician.fifa.Usuario;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author quician
 */
@LocalBean
@Stateless
public class UserManager {
    
    @PersistenceContext //Entity Manager
    private EntityManager em;
    
    public Usuario verificarLogin(String User, String Password){
        
        try{
            StringBuilder  query = new StringBuilder();
            query.append("SELECT u FROM Usuario u ");
            query.append("WHERE u.username = :USERNAME ");
            query.append("AND u.password = :PASSWORD ");
            
            Query q = em.createQuery(query.toString(), Usuario.class);
            q.setParameter("USERNAME", User);
            q.setParameter("PASSWORD", Password);
            
            return (Usuario)q.getSingleResult();
        }
        catch(Exception e){
            Logger.getLogger(UserManager.class.getName()).log(Level.SEVERE,"Error al verificar el login",e); 
            return null;
        }
    }
    
}
